package cn.cmcc.online.smsapi.sdk.util;

import cn.cmcc.online.smsapi.sdk.constant.Constant;
import cn.cmcc.online.smsapi.sdk.db.entity.SysParamEntityManager;

public class RecordFunctionUtil {
	public static int recordFunctionState = 0;// 定义recordstate的32位，每一位代表我们功能的一种状态标记。0000
//										// 0000
//	public static int recordStateTemp = 0;
	public static final int COMPANY_LOGO_STATE_MOVE = 8;// 设置企业logo标记位移数
	public static final int COMPANY_LOGO_STATE = 1 << COMPANY_LOGO_STATE_MOVE;// 设置企业logo标记
	public static final int POP_WINDOW_STATE_MOVE = 7;// 设置弹窗标记位移数
	public static final int POP_WINDOW_STATE = 1 << POP_WINDOW_STATE_MOVE;// 设置弹窗标记
	public static final int SAMPLE_BUBBLE_STATE_MOVE = 6;// 设置简单气泡标记位移数
	public static final int SAMPLE_BUBBLE_STATE = 1 << SAMPLE_BUBBLE_STATE_MOVE;// 设置简单气泡标记
	public static final int CARD_STATE_MOVE = 5;// 设置卡夹标记位移数
	public static final int CARD_STATE = 1 << CARD_STATE_MOVE;// 设置卡夹标记
	public static final int MENU_STATE_MOVE = 4;// 设置菜单标记位移数
	public static final int MENU_STATE = 1 << MENU_STATE_MOVE;// 设置菜单标记
	public static final int RICH_BUBBLE_STATE_MOVE = 3;// 这种丰富气泡弹窗标记位移数
	public static final int RICH_BUBBLE_STATE = 1 << RICH_BUBBLE_STATE_MOVE;// 这种丰富气泡弹窗标记
	public static final int NOTIFY_STATE_MOVE = 2;// 设置通知栏标记位移数
	public static final int NOTIFY_STATE = 1 << NOTIFY_STATE_MOVE;// 设置通知栏标记
	public static final int NUMBER_STATE_MOVE = 1;// 设置号码识别标记位移数
	public static final int NUMBER_STATE = 1 << NUMBER_STATE_MOVE;// 设置号码识别标记

	// 比如：定义menu菜单功能为第4位标记，如果用户点击menu菜单，则此标记为设置为1//recordState
	// 的低字节的第4位设置为1，其他位不变；

	// 设置功能状态标记
	public static void setFunctionState(int state) {
		int recordState  = 0; 
		String res = SysParamEntityManager.getStringParam(Constant.getContext(), Constant.RECORD_FUNCTION_STATE);
		if (!(res == null)){
			recordState = Integer.parseInt(res);
		}
		int recordStateTemp = recordState | state;// 把设置的参数state和recordState
		recordFunctionState = recordStateTemp;
		if (recordStateTemp != recordState){
			SysParamEntityManager.setParam(Constant.RECORD_FUNCTION_STATE, "" + recordStateTemp);
		}
	}

	// 去掉功能状态标记
	public static void removeFunctionState(int state) {
		int recordState  = Integer.parseInt(SysParamEntityManager.getStringParam(Constant.getContext(), Constant.RECORD_FUNCTION_STATE));
		recordState = recordState & (~state);// 对应的参数state先进行按位取反后再和recordState进行与运算就去掉某一位的状态
		SysParamEntityManager.setParam(Constant.RECORD_FUNCTION_STATE, "" + recordState);
		// 0x40->二进制0100 0000
	}

	// 获取功能状态标记
	public static String getrecordState() {
		if (recordFunctionState == 0){
			String res = SysParamEntityManager.getStringParam(Constant.getContext(), Constant.RECORD_FUNCTION_STATE);
			if (!(res == null)){
				recordFunctionState = Integer.parseInt(res);
			}
		}
		return String.valueOf(recordFunctionState);
	}

	// 是否已经标记状态
	public static Boolean isHasFunctionState(int functionState) {
		int recordState  = Integer.parseInt(SysParamEntityManager.getStringParam(Constant.getContext(), Constant.RECORD_FUNCTION_STATE));
		if ((recordState & functionState) == functionState) {
			return true;
		}
		return false;
	}

	// 获取状态标记
	public static int getFunctionState(int functionState, int moveNum) {
		int recordState  = Integer.parseInt(SysParamEntityManager.getStringParam(Constant.getContext(), Constant.RECORD_FUNCTION_STATE));
		int recordStateTemp = recordState;
		return (recordStateTemp & functionState) >> moveNum;
	}

}
